//===============================================================================
// Microsoft patterns & practices Enterprise Library Contribution
// Resource Application Block
//===============================================================================

using System;
using System.Xml;
using Microsoft.Practices.EnterpriseLibrary.Configuration.Design;
using EntLibContrib.Resource;

#if !NUNIT
using Microsoft.VisualStudio.TestTools.UnitTesting;
#else
using NUnit.Framework;
using TestClass = NUnit.Framework.TestFixtureAttribute;
using TestInitialize = NUnit.Framework.SetUpAttribute;
using TestCleanup = NUnit.Framework.TearDownAttribute;
using TestMethod = NUnit.Framework.TestAttribute;
#endif

namespace EntLibContrib.Resource.Configuration.Design.Tests
{
	[TestClass]
	public class BinaryResourceProviderNodeFixture : ConfigurationDesignHost
	{
		private static ResourceManager internalResources = InternalResourceFactory.GetResourceManager();

		[TestMethod]
		[ExpectedException(typeof(ArgumentNullException))]
		public void PassingNullDataInBinaryResourceProviderThrowsException ()
		{
			new BinaryResourceProviderNode(null);
		}

		[TestMethod]
		public void EnsureBinaryResourceProviderNodePropertyCategoriesAndDescriptions ()
		{
			Assert.IsTrue(ResourceAttributesHelper.AssertResourceDescription(typeof(BinaryResourceProviderNode), "ResourceName", internalResources["BinaryResourceNameDescription"]));
			Assert.IsTrue(ResourceAttributesHelper.AssertResourceCategory(typeof(BinaryResourceProviderNode), "ResourceName", internalResources["CategoryProvider"]));
		}

		[TestMethod]
		public void CanCreateBinaryResourceProviderNodeByDataType ()
		{
			ConfigurationNode node = ServiceHelper.GetNodeCreationService(ServiceProvider).CreateNodeByDataType(typeof(BinaryResourceProviderData), new object[] { new BinaryResourceProviderData() });
			Assert.IsNotNull(node);
			Assert.AreEqual(typeof(BinaryResourceProviderNode), node.GetType());
		}

		[TestMethod]
		public void BinaryResourceProviderNodeTest ()
		{
			string binaryResourceProviderName = "BinaryResourceProvider";
			string resourcePathName = "resourcePathName";
			string resourceBaseName = "resourceBaseName";

			BinaryResourceProviderNode node = new BinaryResourceProviderNode();
			node.Name = binaryResourceProviderName;
			node.ResourceName.PathName = resourcePathName;
			node.ResourceName.BaseName = resourceBaseName;

			Assert.AreEqual(binaryResourceProviderName, node.Name);
			Assert.AreEqual(resourcePathName, node.ResourceName.PathName);
			Assert.AreEqual(resourceBaseName, node.ResourceName.BaseName);

			BinaryResourceProviderData data = (BinaryResourceProviderData)node.ResourceProviderData;
			Assert.AreEqual(binaryResourceProviderName, data.Name);
			Assert.AreEqual(resourcePathName, data.ResourcePathName);
			Assert.AreEqual(resourceBaseName, data.ResourceBaseName);
		}

		[TestMethod]
		public void BinaryResourceProviderDataTest ()
		{
			string binaryResourceProviderName = "BinaryResourceProvider";
			string resourcePathName = "resourcePathName";
			string resourceBaseName = "resourceBaseName";

			BinaryResourceProviderData data = new BinaryResourceProviderData();
			data.Name = binaryResourceProviderName;
			data.ResourcePathName = resourcePathName;
			data.ResourceBaseName = resourceBaseName;
			Assert.AreEqual(binaryResourceProviderName, data.Name);
			Assert.AreEqual(resourcePathName, data.ResourcePathName);
			Assert.AreEqual(resourceBaseName, data.ResourceBaseName);

			BinaryResourceProviderNode node = new BinaryResourceProviderNode(data);
			Assert.AreEqual(binaryResourceProviderName, node.Name);
			Assert.AreEqual(resourcePathName, node.ResourceName.PathName);
			Assert.AreEqual(resourceBaseName, node.ResourceName.BaseName);
		}
	}
}